import React, { Component } from 'react'
import './index.css'

class Footer extends Component {
  handleCheckAll = (e) => {
    this.props.checkAllTodo(e.target.checked)
  }

  render() {
    const { todos, handleAllCheckDelete } = this.props
    // total
    const total = todos.length

    // 已完成个数
    // const successTodos = todos.filter((todo) => {
    // return todo.done
    // })
    // const doneCount = successTodos.length

    const doneCount = todos.reduce((pre, todo) => {
      return pre + (todo.done ? 1 : 0)
    }, 0)

    //
    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={doneCount === total && total > 0}
            onChange={this.handleCheckAll}
          />
        </label>
        <span>
          <span>已完成{doneCount}</span> / 全部{total}
        </span>
        <button className="btn btn-danger" onClick={handleAllCheckDelete}>
          清除已完成任务
        </button>
      </div>
    )
  }
}

export default Footer
